﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace UIFrameWork
{
	public abstract class SingletonMono<T> : MonoBehaviour where T:SingletonMono<T>
	{
		protected static T _Instance = null;

		public static T Instance
		{
			get
			{
				if (_Instance == null)
				{
					_Instance = GameObject.FindObjectOfType<T>();
					if (_Instance == null)
					{
						_Instance = new GameObject("Singletion:::"+typeof(T).ToString()).AddComponent<T>();
						DontDestroyOnLoad(_Instance);
					}
				}
				return _Instance;
			}
		}

		public static T GetSingleton()
		{
			return Instance;
		}
		public SingletonMono()
		{
			Init();
		}
		protected virtual void Init(){}

		private void OnDestroy()
		{
			UnInit();
		}
		protected virtual void UnInit(){}
	}

}

